﻿<%@ Page EnableEventValidation="false" Title="" ValidateRequest="false" Language="C#" MasterPageFile="~/Site1.master"
    AutoEventWireup="True" Inherits="IndoTradingMemberV2.product_new2"
    CodeBehind="new2.aspx.cs" %>

<%@ Register Assembly="MREDKJNumericBox" Namespace="MREDKJ" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="/assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" type="text/css" rel="stylesheet" />
    <style>
        #wholesale .control-label {
            width: 110px;
        }

        #wholesale .controls {
            margin-left: 115px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/js/uploader/ajaxupload.js"></script>
    <link href="/js/fancybox2/jquery.fancybox.css" rel="Stylesheet"
        type="text/css" />
    <script type="text/javascript" src="/js/fancybox2/jquery.fancybox.pack.js"></script>
    <div class="portlet box red">
        <div class="portlet-title">
            <h4><i class="icon-bar-chart"></i>
                <%= Resources.Language.NewProduct %>
            </h4>
        </div>
        <div class="portlet-body">
            <br />
            <asp:Literal ID="litMsg" runat="server"></asp:Literal>
            <div id="postStepStatus" class="dpl-steps clearfix" style="width: 480px; float: left;">
                <div class="step first ">
                    <span class="s-1">1</span> <span class="s-2">
                        <%=Resources.Language.ChooseProductCategory %></span> <span class="s-3"></span>
                </div>
                <div class="step current">
                    <span class="s-1">2</span> <span class="s-2">
                        <%=Resources.Language.FillProductDetails %></span> <span class="s-3"></span>
                </div>
                <div class="step last">
                    <span class="s-1">3</span> <span class="s-2">
                        <%=Resources.Language.AwaitingApproval %></span> <span class="s-3"></span>
                </div>
            </div>
            <br style="clear: both" />


            <div class="control-group">
                <div class="buttonfield">
                    <asp:Button runat="server" ID="btnNext3" CssClass="button" OnClick="btnNext_Click"
                        Text="<%$ Resources:Language,Save %>" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>Product ID</b>
                </label>
                <div class="controls">
                    <%=sProdID %>
                </div>
            </div>
            <%if (oProd.Category != null)
              { %>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%= Resources.Language.Categories %></b>
                </label>
                <div class="controls">
                    <%=oProd.Category.Name %>
                    <asp:Literal ID="ltrChangeCategory" runat="server"></asp:Literal>
                </div>
            </div>
            <%} %>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductNameIndo%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtNama" runat="server" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillProductNameInd %>',STICKY,CAPTION,'<%=Resources.Language.ProductNameIndo%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="rfvName" runat="server" ControlToValidate="txtNama"
                        ErrorMessage="<%$ Resources:Language, FillProductNameInd %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductNameEng%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtNamaEng" Width="400" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillProductNameEng %>',STICKY,CAPTION,'<%=Resources.Language.ProductNameEng%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtNamaEng"
                        ErrorMessage="<%$ Resources:Language, FillProductNameEng %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.OtherProductName%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtOtherName" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillOtherProductName %>',STICKY,CAPTION,'<%=Resources.Language.OtherProductName%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtOtherName"
                        ErrorMessage="<%$ Resources:Language, FillOtherProductName %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.CountryOrigin%><font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <asp:DropDownList ID="ddlCountry" runat="server">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlCountry"
                        ErrorMessage="<%$ Resources:Language, ChooseCountry %>" SetFocusOnError="true"
                        Font-Bold="true" ForeColor="Red" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.ProductGroup%><font color="red">(*)</font>
                    </b>
                </label>
                <div class="controls">
                    <asp:HiddenField ID="hfGroupProduct" runat="server" ClientIDMode="Static"></asp:HiddenField>
                    <span id="parentSpan" runat="server">
                        <asp:DropDownList ID="ddlGroupParent" runat="server" ClientIDMode="Static"></asp:DropDownList>
                        <a href="addproductgroup.aspx?q=<%=sq2.ToString() %>" id="aTambah" name="aTambah">
                            <%=Resources.Language.AddProductGroup%></a> <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.GroupProduct %>',STICKY,CAPTION,'<%=Resources.Language.ProductGroup%>',CENTER);"
                                onmouseout="return nd();">
                                <img src="/images/question.gif" /></a><br />
                    </span>
                    <asp:DropDownList ID="ddlGroupProduct" runat="server" ClientIDMode="Static">
                    </asp:DropDownList>

                    <br />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="<%$Resources:Language,ReqGroupProduct %>" ControlToValidate="ddlGroupParent" Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
                        Font-Bold="true" EnableClientScript="false"></asp:RequiredFieldValidator>
                </div>
            </div>




            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.Weight%>
                    </b>
                </label>
                <div class="controls">
                    <asp:DropDownList ID="ddlWeight" runat="server" Width="150px">
                        <asp:ListItem Text="Gram (g)" ID="gram"></asp:ListItem>
                        <asp:ListItem Text="Kilogram (kg)" ID="kilogram"></asp:ListItem>
                    </asp:DropDownList>

                    <cc1:NumericTextBox ID="txtWeight" runat="server" AllowDecimal="true" Width="150px"></cc1:NumericTextBox>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b><%=Resources.Language.Brand %></b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtBrand" runat="server"></asp:TextBox>
                    <% Page.ClientScript.RegisterStartupScript(GetType(), "autocomplete-brand", @"
$(function() {
    var cache = {};
    $( ""#" + txtBrand.ClientID + @""" ).autocomplete({
      minLength: 2,
      source: function( request, response ) {
        var term = request.term;
        if ( term in cache ) {
          response( cache[ term ] );
          return;
        }
		$.ajax({
			url: '/ajaxmethod.asmx/SearchBrand',
			dataType: 'json',
			data:JSON.stringify(request),
			cache: false,
			type: 'POST',
			contentType: 'application/json; charset=utf-8',
			success: function(doc) {
				cache[ term ] = doc.d;
				response( doc.d );
			}
		});
      }
    });
  });", true); %>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>SKU</b>
                </label>
                <div class="controls">
                    <asp:TextBox ID="txtSku" runat="server" Columns="50" MaxLength="128" EnableViewState="false"></asp:TextBox>
                    <br />
                    <font size="1" color="red"><%=Resources.Language.SKUDesc %></font>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>Minimum Order<font color="red">(*)</font></b>
                </label>
                <div class="controls">
                    <cc1:CurrencyTextBox ID="txtMOQ" runat="server" allowdecimal="true" type="number" ClientIDMode="Static"></cc1:CurrencyTextBox>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b><%if (oComp.IsExportCompany != null && oComp.IsExportCompany)
                         { %>F.O.B

                        <%} %>
                        <%=Resources.Language.Price%><font color="red">(*)</font></b>
                </label>
                <div class="controls">

                    <asp:DropDownList ID="ddlCurrency" runat="server" Width="90px" ClientIDMode="Static">
                    </asp:DropDownList>
                    <cc1:NumericTextBox ID="txtPrice" runat="server" AllowDecimal="true" Width="120px" ClientIDMode="Static"></cc1:NumericTextBox>
                    /
                 <asp:TextBox ID="txtUnitPrice" runat="server" Columns="10" Text="Unit" Width="70px"></asp:TextBox>
                    e.g
                <%=Resources.Language.unit %>
                    <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillPrice0 %>',STICKY,CAPTION,'<%=Resources.Language.Price%>');"
                        onmouseout="return nd();">
                        <img src="/images/question.gif" /></a>
                    <asp:RequiredFieldValidator ID="rfvPrice" runat="server" ControlToValidate="txtPrice"
                        ErrorMessage="<%$Resources:Language,FillPrice0 %>" SetFocusOnError="true" ForeColor="Red"
                        Font-Bold="true" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b><%=Resources.Language.SellingType %></b>
                </label>
                <div class="controls">
                    <asp:DropDownList ID="ddlSellingType" runat="server" Width="290px" ClientIDMode="Static">
                        <asp:ListItem Value="" Text="<%$ Resources:Language,ChooseSellingType %>"></asp:ListItem>
                        <asp:ListItem Value="Wholesale" Text="<%$ Resources:Language,WholeSale %>"></asp:ListItem>
                        <asp:ListItem Value="Retail" Text="<%$ Resources:Language,Retail %>"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="ddlSellingType"
                        ErrorMessage="<%$Resources:Language,ChooseSellingType %>" SetFocusOnError="true" ForeColor="Red"
                        Font-Bold="true" EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
                </div>
            </div>

            <div class="control-group" id="ctrlWholeSale" style="display: none;" runat="server">
                <div class="controls">
                    <div class="portlet box green portlet-wholesale">
                        <div class="portlet-title">
                            <h4><i class="icon-reorder"></i>
                                <%= Resources.Language.WholeSalePrice %> 
                            </h4>
                            <!--<div class="tools">
                                <a href="//" onclick="return false;" class="control_box_collapse collapse"></a>
                            </div>-->
                        </div>
                        <div class="portlet-body" id="wholesale">
                            <span id="spanMsg" style="color: red; font-weight: bold;"></span>
                            <asp:ListView runat="server" ID="lvGrosir" DataKeyNames="ID" InsertItemPosition="FirstItem">
                                <%--<LayoutTemplate>
										<div class="control-group"><asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder></div>
									</LayoutTemplate>--%>
                                <ItemTemplate>
                                    <div class="control-group">
                                        <label class="control-label">
                                            <%=Resources.Language.Price%> Grosir <font color="red">(*)</font>
                                        </label>
                                        <div class="controls">

                                            <asp:TextBox ID="txtPrice" runat="server" Width="100px" CssClass="numeric price" Text='<%# Bind("UnitPrice") %>'></asp:TextBox>
                                            <%=Resources.Language.ForMOQ %>
                                            <asp:TextBox ID="txtMoQ" runat="server" Width="100px" CssClass="numeric moq" Text='<%# Bind("minQty") %>' type="number"></asp:TextBox><asp:HiddenField ID="txtID" runat="server" Value='<%# Bind("ID") %>'></asp:HiddenField>

                                            <asp:RequiredFieldValidator ID="rfvPrice" runat="server" ControlToValidate="txtPrice"
                                                ErrorMessage="<%$Resources:Language,FillPrice0 %>" SetFocusOnError="true" ForeColor="Red"
                                                Font-Bold="true" EnableClientScript="false" Display="Dynamic" ValidationGroup="wholesale"></asp:RequiredFieldValidator>
                                            <a href="//" onclick="return false;" class="btn green btn-edit">Edit</a>
                                            <a href="//" onclick="return false;" class="btn grey btn-delete">Delete</a>
                                        </div>
                                    </div>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <div class="control-group">
                                        <label class="control-label">
                                            <%=Resources.Language.Price%> Grosir <font color="red">(*)</font>
                                        </label>
                                        <div class="controls">
                                            <asp:TextBox ID="txtPrice" runat="server" Width="100px" CssClass="numeric price" placeholder='price' Text='<%# Bind("UnitPrice") %>'></asp:TextBox>
                                            <%=Resources.Language.ForMOQ %>
                                            <asp:TextBox ID="txtMoQ" runat="server" Width="100px" CssClass="numeric moq" placeholder='quantity' Text='<%# Bind("minQty") %>' type="number"></asp:TextBox>


                                            <asp:RequiredFieldValidator ID="rfvPrice" runat="server" ControlToValidate="txtPrice"
                                                ErrorMessage="<%$Resources:Language,FillPrice0 %>" SetFocusOnError="true" ForeColor="Red"
                                                Font-Bold="true" EnableClientScript="false" Display="Dynamic" ValidationGroup="wholesale"></asp:RequiredFieldValidator>
                                            <a href="//" onclick="return false;" class="btn green btn-add">Add</a>
                                        </div>
                                    </div>
                                </InsertItemTemplate>
                            </asp:ListView>
                        </div>
                    </div>
                </div>
            </div>


            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.Photo%></b><br />
                </label>
                <div class="controls">
                    <div id="upload">
                        <span><%=Resources.Language.ChoosePhoto%></span>
                    </div>
                    <img src="/images/loading.gif" alt="" id="loading" style="display: none" />
                    <span id="status"></span>
                    <%= Resources.Language.MaxDisplayImg%>
                (480 x 640) pixel<br />
                    <div id="photos">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.DescriptionInd %><font color="red">(*)</font></b> <a href="javascript:void(0);" onclick="return overlib('<%=Resources.Language.FillDescriptionInd %>',STICKY,CAPTION,'<%=Resources.Language.DescriptionInd %>');"
                            onmouseout="return nd();">
                            <img src="/images/question.gif" /></a>
                    <br />
                    <br />
                    <br />
                    <a href='http://translate.google.com' target="_blank">[<%= Resources.Language.HelpTranslation %>]</a>
                    <br />
                    <br />
                    <input type="button" id="idInsertImageDetilInd" value='<%= Resources.Language.InsertImage %>' class="btnControl" />
                </label>
                <div class="controls">
                    <textarea class="ckeditor" cols="80" id="txtDetilIndo1" name="txtDetilIndo1" rows="10" runat="server"></textarea>
                    <asp:RequiredFieldValidator ID="rfvDetilIndo" runat="server" ControlToValidate="txtDetilIndo1"
                        EnableClientScript="false" ForeColor="Red" ErrorMessage="<%$ Resources:Language,FillDescriptionInd %>"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    <b>
                        <%=Resources.Language.DescriptionEng %><font color="red">(*)</font></b> <a style="clear: both" href="javascript:void(0);"
                            onclick="return overlib('<%=Resources.Language.FillDescriptionEng %>',STICKY,CAPTION,'<%=Resources.Language.DescriptionEng %>');"
                            onmouseout="return nd();">
                            <img src="/images/question.gif" /></a>
                    <br />
                    <br />
                    <br />
                    <a href='http://translate.google.com' target="_blank">[<%= Resources.Language.HelpTranslation %>]</a>
                    <br />
                    <br />
                    <input type="button" id="idInsertImageDetilEng" value='<%= Resources.Language.InsertImage %>' class="btnControl" />
                </label>
                <div class="controls">
                    <textarea class="ckeditor" cols="80" id="txtDetilEng1" name="txtDetilEng1" rows="10" runat="server"></textarea>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDetilEng1"
                        EnableClientScript="false" ForeColor="Red" ErrorMessage="<%$ Resources:Language,FillDescriptionEng %>"></asp:RequiredFieldValidator>
                </div>
            </div>
            <div class="control-group">

                <asp:Button ID="btnNext" runat="server" Text="<%$ Resources:Language,Save %>" CssClass="button"
                    OnClick="btnNext_Click" />

                <input type="hidden" id="CoID" value='<%=IndoTradingLib.Utils.Cookie.CompanyID %>' />
            </div>


            <script type="text/javascript" src="/js/overlib_mini.js"></script>
            <script type="text/javascript">
                function makeSublist(parent, child, isSubselectOptional, childVal) {

                    $("body").append("<select style='display:none' id='" + parent + child + "'></select>");
                    $('#' + parent + child).html($("#" + child + " option"));
                    var parentValue = $('#' + parent).attr('value');
                    if (isSubselectOptional) $('#' + child).prepend("<option value='none'> --- </option>");
                    $('#' + child).html($('#' + child + " option").add($("#" + parent + child + " .sub_" + parentValue).clone()));
                    childVal = (typeof childVal == "undefined") ? "" : childVal;
                    $("#" + child).find('option[value="' + childVal + '"]').attr("selected", true);
                    $('#' + parent).change(
			            function () {
			                var parentValue = $('#' + parent).attr('value');
			                $('#' + child).html($("#" + parent + child + " .sub_" + parentValue).clone());
			                if (isSubselectOptional) $('#' + child).prepend("<option value='none'> --- </option>");
			                $('#' + child).trigger("change");
			                if ($('#' + child + ' option').length > 0) {
			                    $('#' + child).css("display", "");
			                }
			                else {
			                    //$('#' + child).css("display", "none");
			                }
			                $('#' + child).focus();
			            }
		            );
                }
                $(function () { makeSublist('<%=ddlGroupParent.ClientID%>', '<%=ddlGroupProduct.ClientID%>', true, ''); });
                function CloseDialog() {
                    $.fancybox.close();
                    //window.location = '<%= Request.RawUrl %>';
                }

                function Count(text, long) {

                    var maxlength = new Number(long);
                    if (text.value.length > maxlength) {
                        text.value = text.value.substring(0, maxlength);

                    }
                }

                $(document).ready(function () {
                    function UpdateProductPriceAndMOQ() {
                        $.ajax({
                            type: "POST",
                            url: '/AjaxMethod.asmx/UpdateProductPrice',
                            data: { ProdID: "<%=sEncProdID%>", MOQ: $("#txtMOQ").val(), Price: $("#txtPrice").val(), Currency: $("#ddlCurrency").val() },
                            success: function (response) {

                            },
                            failure: function (msg) {

                            }
                        });
                    }
                    $("#txtMOQ").change(function () {
                        UpdateProductPriceAndMOQ();
                    });
                    $("#txtPrice").change(function () {
                        if ($("#txtPrice").val() != "") {
                            UpdateProductPriceAndMOQ();
                        }
                    });

                    $("#aTambah").fancybox({
                        'type': 'iframe',
                        'width': 600,
                        'height': 600,
                        onClosed: function () {
                            $("#<%= ddlGroupParent.ClientID %>").empty();
                            $("#<%= ddlGroupParent.ClientID %>").append("<option>Loading......</option>");

                            $.ajax({
                                type: "POST",
                                url: "/AjaxMethod.asmx/GetCompanyProductGroup",
                                data: "{'CompanyID': '" + $("#CoID").val() + "'}",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (response) {
                                    var groups = response.d;
                                    var bval = $("#<%= ddlGroupProduct.ClientID %>").val();
                                    var bval2 = $("#<%= ddlGroupParent.ClientID %>").val();
                                    $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").empty();
                                    $("#<%= ddlGroupParent.ClientID %>").empty();
                                    $.each(groups, function (index, group) {

                                        if (!group.IsChild) {
                                            if (index == groups.length - 1 && bval2 == "") {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                            else if (bval2 != "" && group.GroupID == bval) {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                            else {
                                                $("#<%= ddlGroupParent.ClientID %>").append("<option value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                            }
                                    } else {
                                        if (group.ParentID == null) {
                                            strcpar = '';
                                        } else strcpar = group.ParentID;

                                        if (index == groups.length - 1 && bval == "") {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "' selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }
                                        else if (bval != "" && group.GroupID == bval) {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "' selected value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }
                                        else {
                                            $("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>").append("<option class='sub_" + strcpar + "'  value ='" + group.GroupID + "'>" + group.GroupName + "</option>");
                                        }

                                }


                                    });
                                    //$('#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %>').html($("#<%= ddlGroupParent.ClientID %> option"));
                                    $('#<%=ddlGroupProduct.ClientID%>').html($("#<%= ddlGroupParent.ClientID+ddlGroupProduct.ClientID %> .sub_" + $("#<%= ddlGroupParent.ClientID %>").val()).clone());
                                    $("#hfGroupProduct").val($("#<%= ddlGroupProduct.ClientID %>").val());
                                },
                                failure: function (msg) {
                                    alert(msg);
                                    $("#<%= ddlGroupProduct.ClientID %>").empty();
                                    $("#<%= ddlGroupParent.ClientID %>").empty();
                                }
                            });
                        }
                    });

                    loadPhotos();
                    $(".btnDelete").live('click', function () {
                        if (window.confirm("<%=Resources.Language.DeleteFoto %>")) {
                            $.ajax({
                                type: "POST",
                                url: '/product/photo.aspx?q=<%=sQuery%>',
                                data: { cmd: "del", id: $(this).attr('rel') },
                                success: function (response) {
                                    $('#photos').html(response);
                                },
                                failure: function (msg) {
                                    alert(msg);
                                }
                            });
                        }
                    });

                    $("#<%= ddlGroupProduct.ClientID%>").change(function () {
                        $("#hfGroupProduct").val($("#<%= ddlGroupProduct.ClientID%>").val());
                    });

                });


            </script>
            <asp:Literal ID="ltrFancyBox" runat="server"></asp:Literal>
        </div>
    </div>

</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="footer">
    <script type="text/javascript" src="/js/currency.js"></script>
    <script>

        function showWholeSalePrice() {

            $("#<%=ctrlWholeSale.ClientID%>").show();
            //Save Price, MOQ ,Currency using AJAX

        }
        function hideWholeSalePrice() {
            $("#<%=ctrlWholeSale.ClientID%>").hide();

        }
        $(document).ready(function () {
            //Hide and show wholesale price
            $('#ddlSellingType').live('change', function () {
                if ($('#ddlSellingType').val() == "Wholesale") {
                    showWholeSalePrice();
                }
                else {
                    hideWholeSalePrice();
                }

            });

            CKEDITOR.replace('<%=txtDetilIndo1.UniqueID%>', {
                extraPlugins: 'autogrow',
                removePlugins: 'resize',
            });

            CKEDITOR.replace('<%=txtDetilEng1.UniqueID%>', {
                extraPlugins: 'autogrow',
                removePlugins: 'resize'
            });
            CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].on('contentDom', function () {
                this.document.on('click', function (event) {
                    //my code

                    if (CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].getData().toLowerCase().indexOf("isi deskripsi produk anda") >= 0) {
                        CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].setData('');
                    }

                });
            });
            CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].on('contentDom', function () {
                this.document.on('click', function (event) {

                    if (CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].getData().toLowerCase().indexOf("fill product description") >= 0) {
                        CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].setData('');
                    }
                });
            });
            $('#idInsertImageDetilInd').fancybox({
                'href': '/product/photogallery.aspx?q=<%=sq.ToString()%>&lang=id',
                'type': 'iframe',
                'width': 420,
                'height': 600
            });
            $('#idInsertImageDetilEng').fancybox({
                'href': '/product/photogallery.aspx?q=<%=sq.ToString()%>&lang=en',
                'type': 'iframe',
                'width': 420,
                'height': 600
            });
        });

        function loadPhotos() {
            $.get('/product/photo.aspx?q=<%=sQuery%>', function (data) {
                if (data != 'empty') {
                    $('#photos').html(data);
                }
            });
        }

        function insertImgToDetilInd(data) {
            var img = '<img src="' + data + '" />';
            CKEDITOR.instances['<%=txtDetilIndo1.ClientID%>'].insertHtml(img);
            $.fancybox.close();
        }
        function insertImgToDetilEng(data) {
            var img = '<img src="' + data + '" />';
            CKEDITOR.instances['<%=txtDetilEng1.ClientID%>'].insertHtml(img);
            $.fancybox.close();
        }
        function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = decodeURIComponent(hash[1]);
            }
            return vars;
        }
       // $(function () {
            setTimeout(function () {
                var btnUpload = $('#upload');
                var loading = $('#loading');
                var status = $('#status');

                new AjaxUpload(btnUpload, {
                    action: '/product/uploader.ashx?q=<%=sQuery%>',
                    name: 'uploadfile',
                    onSubmit: function (file, ext) {
                        if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                            status.text('Only JPG, PNG or GIF files are allowed');
                            return false;
                        }

                        btnUpload.hide();
                        loading.show();
                    },
                    onComplete: function (file, response) {
                        status.html('');
                        loading.hide();
                        btnUpload.show();

                        var result = $.parseJSON(response);
                        if (result.IsSuccess) {
                            loadPhotos();
                            status.html(result.Message);
                        } else {
                            status.html(response);
                        }
                    }
                });

            }, 5);



            $(document).on("keypress", '.numeric', function (e) {
                e = e || window.event;
                var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
                var charStr = String.fromCharCode(charCode);
                if (/\d/.test(charStr)) {
                    if ($(this).val() == '' && charStr == '0') {
                        return false;
                    }
                    return true;
                }
                return false;
            });

            $(document).on("paste", '.numeric', function (e) {
                e.preventDefault();
                return false;
            });
            var inProgress = false;
            $(document).on("click", '#wholesale .btn-add', function (e) {
                $(".btn-add").text("Loading");
                $("#spanMsg").text("");
                e.preventDefault();
                if (!inProgress) {
                    inProgress = true;

                    var oPrice = {};
                    oPrice.ProdID = getUrlVars()["q"];
                    var $parent = $(this).closest('div.controls');
                    oPrice.Price = $parent.find('input.price').val();
                    oPrice.qty = $parent.find('input.moq').val();

                    if (oPrice.Price == '' || oPrice.qty == '' || oPrice.qty == '0' || oPrice.qty == '1') {
                        alert('<%=Resources.Language.QtyMustBiggerThanMOQ%>');
                        e.preventDefault();
                        inProgress = false;
                        $(".btn-add").text("Add");
                        return false;
                    }
                    sendWholeSale("/ajaxmethod.asmx/InsertProductWholeSalePrice", oPrice, function (response) {
                        var data = response.d;
                        if (data.err != undefined && data.err != '') {
                            alert(data.err);
                        }
                        else {
                            $parent.find('input.price').val('');
                            $parent.find('input.moq').val('');

                            $('#wholesale').append(
                                $('<div class="control-group" />').append($('<label class="control-label">Harga Grosir<font color="red">(*)</font></label>')).append($('<div class="controls">').append($('<input name="txtPrice[]" type="text" class="numeric price" style="width:100px;" value="' + data.price + '"> <%=Resources.Language.ForMOQ%> <input name="txtMoQ[]" type="text" class="numeric moq" style="width:100px;" value="' + data.qty + '"><input name="txtID[]" type="hidden" value="' + data.id + '"> <a href="//" onclick="return false;" class="btn green btn-edit">Edit</a> <a href="//" onclick="return false;" class="btn grey btn-delete">Delete</a>')))
                                );
                            $("#spanMsg").text("Added Successfully");
                        }

                    });
                    inProgress = false;
                    $(".btn-add").text("Add");
                    // $(".btn-add").text("Add");
                    return false;
                }
            });



            $(document).on("click", '#wholesale .btn-edit', function (e) {
                $("#spanMsg").text("");
                $(".btn-edit").text("Updating...");
                var oPrice = {};
                oPrice.ProdID = getUrlVars()["q"];

                var $parent = $(this).closest('div.controls');
                oPrice.ID = $parent.find('input[type=hidden]').val();
                oPrice.Price = $parent.find('input.price').val();
                oPrice.qty = $parent.find('input.moq').val();
                if (oPrice.Price == '' || oPrice.qty == '' || oPrice.qty == '0' || oPrice.qty == '1') {
                    alert('Please Fill Price and qty with correct number');
                    e.preventDefault();
                    return false;
                }
                sendWholeSale("/ajaxmethod.asmx/updateproductwholesaleprice", oPrice, function (response) {
                    var data = response.d;
                    if (data.err != undefined && data.err != '') {
                        alert(data.err);
                    } else if (data.id != oPrice.ID) {
                        alert("response fail");
                        location.reload();
                    } else {
                        $parent.find('input.price').val(data.price);
                        $parent.find('input.qty').val(data.qty);
                        $("#spanMsg").text("(Update Success)");
                    }
                });

                e.preventDefault();
                $(".btn-edit").text("Edit");
                return false;
            });

            $(document).on("click", '#wholesale .btn-delete', function (e) {
                var oPrice = {};
                oPrice.ProdID = getUrlVars()["q"];

                var $parent = $(this).closest('div.controls');
                oPrice.ID = $parent.find('input[type=hidden]').val();
                sendWholeSale("/ajaxmethod.asmx/DeleteProductWholeSalePrice", oPrice, function (response) {
                    var data = response.d;
                    if (data.err != undefined && data.err != '') {
                        alert(data.err);
                    } else {
                        $parent.closest('div.control-group').remove();
                    }
                });

                e.preventDefault();
                return false;
            });

            function sendWholeSale(Url, oPrice, funcSuccess) {
                $.ajax({
                    type: "POST",
                    url: Url,
                    data: JSON.stringify(oPrice),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: funcSuccess
                });

            }

            function expand($e) {
                var $sender = $($e).closest('div.portlet').find('a.control_box_collapse');
                $sender.removeClass('expand');
                $sender.unbind('click');
                $sender.addClass('collapse');
                $e.slideDown('slow', function () {
                    $sender.bind('click', function (e) {
                        collapse($e); e.preventDefault();
                        return false;
                    });
                });
            }
            function collapse($e) {
                var $sender = $($e).closest('div.portlet').find('a.control_box_collapse');
                $sender.removeClass('collapse');
                $sender.unbind('click');
                $sender.addClass('expand');
                $e.slideUp('slow', function () {
                    $sender.bind('click', function (e) {
                        expand($e); e.preventDefault();
                        return false;
                    });
                });
            }
            $('a.control_box_collapse.collapse').unbind('click').click(function (e) {
                collapse($(this).closest('div.portlet').find('div.portlet-body'));
                e.preventDefault();
                return false;
            });
            $('a.control_box_collapse.expand').unbind('click').click(function (e) {
                expand($(this).closest('div.portlet').find('div.portlet-body'));
                e.preventDefault();
                return false;
            });
        //});
    </script>
</asp:Content>
